//
//  ZQHomeViewController.swift
//  Timor微博
//
//  Created by 周周旗 on 2019/2/26.
//  Copyright © 2019 ZQ. All rights reserved.
//

import UIKit

//全局变量，最好加上private ，不然整个命名空间都可以访问
let cellID = "cellID"

class ZQHomeViewController: ZQBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    /// 数据
    private lazy var listViewModel = ZQWBStatusListViewModel()
    
    override func loadData() {
        listViewModel.loadStatus(pullUp: self.isPullRefresh) { (isSuccess) in
            //控制刷新
            self.isPullRefresh = false
            self.refreshController?.endRefreshing()
            self.tableview?.reloadData()
        }
    }
    
    /// 显示好友
    @objc private func showFriends(){
         print(#function)
        let vc = ZQDemoController.init()
        navigationController?.pushViewController(vc, animated: true)
    }
}

// MARK: - 数据源方法
extension ZQHomeViewController{
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listViewModel.statusList.count;
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //1.取cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        
        //2.设置cell
        
        cell.textLabel?.text =  listViewModel.statusList[indexPath.row].text
        
        //3.返回cell
        return cell
    }
}

// MARK: - UI 设置
extension ZQHomeViewController{
    override func setupTableView() {
        super.setupTableView()
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        tableview?.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
    }
}
